<body class="iframe">
    <div class="edit">
        <div class="frame-header">
            <h2><i class="layui-icon">&#xe705;</i>模板管理</h2>
        </div>
        <h4 class="layui-bg-dark frame-title"><i class="layui-icon">&#xe65f;</i>添加模板</h4>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">模板简介</label>
                <div class="layui-input-block">
                    <input type="text" name="brief" required lay-verify="required" placeholder="请输入简介" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline">
                    <input type="text" name="sort" required lay-verify="required|number"  autocomplete="off" class="layui-input typesort" value="0">
                </div>
                <div class="layui-form-mid layui-word-aux">值越大,越靠前(0-99)</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮件主题</label>
                <div class="layui-input-block">
                    <input type="text" name="subject" required lay-verify="required" placeholder="请输入主题" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">防检测</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="ismessy" lay-skin="switch">
                </div>
                <div class="layui-form-mid layui-word-aux">开启此项,邮件正文中的竖线之间的内容会被随机打乱,调用方式如下  '|你的内容|'</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">附件地址</label>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" class="layui-input localurl">
                    <input type="hidden" name="attachurl" class="serverurl"></input>
                </div>
                <button type="button" class="layui-btn" id="uploadattachment"><i class="layui-icon">&#xe67c;</i>上传附件</button>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">邮件正文</label>
                <div class="layui-input-block">
<!--                    <textarea name="content" placeholder="请输入内容" class="layui-textarea"></textarea>-->
                    <script id="editor" type="text/plain" style="width:800px;height:500px;" name="content"></script>
                </div>
                
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="addtemplate">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>

    </div>
</body>

<script type="text/javascript" charset="utf-8" src="<?=base_url()?>public/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="<?=base_url()?>public/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="<?=base_url()?>public/ueditor/lang/zh-cn/zh-cn.js"></script>




<script>
    var ue = UE.getEditor('editor');
    layui.use(['form', 'upload'], function () {
        var form = layui.form, upload = layui.upload;
        
        //上传文件
        var uploadInst = upload.render({
            elem: '#uploadattachment',
            accept: 'file',
            size:102400,//最大支持100m的文件上传
            exts:'png|gif|jpg|jpeg|txt|xls|mp4|wav',
            auto: false,
            url: '<?= site_url("upload/do_upload") ?>',
            choose: function (obj) {
                layer.confirm('确定上传此附件?', function (index) {
                    obj.preview(function (index, file, result) {
                        $(".localurl").val(file.name);
                        layer.load();
                        obj.upload(index, file);
                    });
                });
            },
            done: function (redata) {
                if (redata.errno == '666') {
                    layer.closeAll('loading');
                    layer.msg(redata.error);
                    $(".serverurl").val(redata.uploadInfo.upload_data.file_name);
                } else {
                    layer.msg(redata.error);
                }
            },
            error: function () {
                layer.msg('上传异常');
            }
        });

        //添加模板
        form.on('submit(addtemplate)', function (data) {
            let brief = data.field.brief;//模板简介
            let subject = data.field.subject;//邮件主题
            let content = data.field.content;//邮件正文
            let attachment = data.field.attachurl;//附件地址
            let sort = data.field.sort;//排序
            let ismessy = data.field.ismessy=='on'?1:0;//防检测
            let url = '<?= site_url('template/add_template') ?>';
            let jsonData = {
                'brief': brief,
                'subject': subject,
                'content': content,
                'attachment': attachment,
                'sort': sort,
                'ismessy': ismessy
            };
            noCallbackRequest(url,jsonData,layer);
            return false;
        });
        
    });
</script>

</html>